package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroup;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.logic.rank.UnionRankMsgModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.commonactivity.CommonActivityProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.CommonActivityRankMgr;
import com.yanqu.road.server.manger.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.server.manger.activity.tonbing.TonBingMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.Map;
import java.util.Objects;

@Cmd(code = Protocol.S_PEAK_UNION_MAX_ABILITY_RANK_LOCK, desc = "活动跨服锁定报名期排行的请求")
public class PeakActivityUnionMaxAbilityRankLockCmd extends AbstractCommand {

    private int activityId;
    private int groupId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CommonActivityProto.CommonActivityRankListReqMsg reqMsg = CommonActivityProto.CommonActivityRankListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        groupId = reqMsg.getGroupId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        RankProto.GetActivityUnionRankListRespMsg.Builder respMsg = RankProto.GetActivityUnionRankListRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        UnionRankMsgModel model = CommonActivityRankMgr.getUnionRankMsgModelByGroup(activityId, groupId);
        if (null != model) {
            ActivityInfo activityInfo = ActivityMgr.getOpenActivityInfo(activityId);
            model.setNeedSendToActivityCross(true);
            CrossUnionProto.CrossUnionGetMaxAbilityUnionRankListReq.Builder crossReqMsg = CrossUnionProto.CrossUnionGetMaxAbilityUnionRankListReq.newBuilder();
            crossReqMsg.setActivityId(activityId);
            crossReqMsg.addAllServerIds(activityInfo.getServerIdList());
            crossReqMsg.setRankNum(model.getRankNum());
            crossReqMsg.setActivityEndTime(activityInfo.getEndShowTime());
            crossReqMsg.setGroupId(model.getGroupId());
            GamePlayerMgr.sendPacket(0, YanQuMessageUtils.buildMessage(Protocol.C_UNION_GET_MAX_ABILITY_UNION_RANK_LIST, crossReqMsg));
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
